package com.guomao.function;

import java.util.function.Consumer;

public class ConsumerDemo {


    public static void main(String[] args) {


        String str = "hello world";

        consumerString(str, System.out::println);

        /*consumerString(str, (s) -> {
            String s1 = s.toUpperCase();
            System.out.println(s1);
        });
*/

      /*  consumerString(str, (s1) -> {
            String java = s1.concat("java");
            System.out.println(java);
        }, (s2) -> {
            String s = new StringBuilder(s2).reverse().toString();
            System.out.println(s);
        });*/

      /*  String[] names = {"root,30", "admin,50", "lisi,65"};
        //lambda表达式中()参数列表的变量取决于定义的方法传递的参数
        consumerNameArr(names, (s1) -> {
            String[] split = s1.split(",");
            String name = split[0];
            System.out.println(name);
        }, (s2) -> {
            String[] split = s2.split(",");
            String age = split[1];
            System.out.println(age);
        });*/
    }

    public static void consumerString(String s, Consumer<String> c) {
        c.accept(s);
    }


    public static void consumerString(String s, Consumer<String> c1, Consumer<String> c2) {

        c1.andThen(c2).accept(s);
    }


    public static void consumerNameArr(String[] arr, Consumer<String> c1, Consumer<String> c2) {
        for (String s : arr) {
            c1.andThen(c2).accept(s);
        }
    }
}
